package com.foyekoo.project001.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.flyco.tablayout.SlidingTabLayout;
import com.foyekoo.project001.R;
import com.foyekoo.project001.fragment.BaseFragment;
import com.foyekoo.project001.fragment.BaseSetFragment;
import com.foyekoo.project001.fragment.BillFragment;
import com.foyekoo.project001.fragment.GameSetFragment;
import com.foyekoo.project001.fragment.SystemSetFragment;
import com.foyekoo.project001.service.UsbService;
import com.foyekoo.project001.utils.BaseFragmentAdapter;
import com.foyekoo.project001.utils.NoScrollViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindInt;
import butterknife.BindView;
import butterknife.ButterKnife;

public class BackgroundActivity extends BaseActivity {

    String[] tagTitle = {"账目查询 ","基础设置 ","游戏设置","系统设置"};

    private ArrayList<BaseFragment> fragments = new ArrayList<>();

    private BillFragment billFragment;
    private BaseSetFragment baseSetFragment;
    private GameSetFragment gameSetFragment;
    private SystemSetFragment systemSetFragment;

    @BindView(R.id.sliding_tab)
    public SlidingTabLayout slidingTabLayout;

    @BindView(R.id.view_pager)
    public NoScrollViewPager viewPager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setScreen();
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_backgroung);
        ButterKnife.bind(this);
        initFragment();
    }

    public void setScreen() {
        //去掉标题栏
        this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        //全屏显示
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //去掉虚拟按键
        setNavigationBarVisibility(false);
    }
    public void setNavigationBarVisibility(boolean visible) {
        int flag = 0;
        if (!visible) {
            flag = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
        }

        getWindow().getDecorView().setSystemUiVisibility(flag);
    }


    private void initFragment(){
        gameSetFragment = new GameSetFragment();
        baseSetFragment = new BaseSetFragment();
        billFragment = new BillFragment();
        systemSetFragment = new SystemSetFragment();

        fragments.add(billFragment);
        fragments.add(baseSetFragment);
        fragments.add(gameSetFragment);
        fragments.add(systemSetFragment);


        viewPager.setNoScroll(true);
        viewPager.setOffscreenPageLimit(4);
        viewPager.setAdapter(new BaseFragmentAdapter(getSupportFragmentManager(),fragments,tagTitle));
        slidingTabLayout.setViewPager(viewPager,tagTitle);
    }
}
